package com.yuzhihao.writejvm.attributes.runtimeva;

import com.yuzhihao.writejvm.clazz.ClassInfo;
import com.yuzhihao.writejvm.read.Parse;
import com.yuzhihao.writejvm.read.ReadClassFileFatory;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.log4j.Log4j2;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Each entry in the parameter_annotations table represents all of the run-time visible annotations on the declaration of a single formal parameter.
 *
 * @author yzh
 * @since 2021年12月11日15:23:50
 */
@Data
@Log4j2
public class ParameterAnnotations implements Parse{

    private int num_annotations_u2 = 2;

    private int num_annotations;

    private List<Annotation> annotations = new ArrayList<>();

    @Override
    public void parse(DataInputStream dis, ClassInfo ci) {
        try {
            this.num_annotations = Parse.byteToInt(this.num_annotations_u2, dis);

            int i = 0;
            while (i < this.num_annotations){
                Annotation annotation = new Annotation();
                annotation.parse(dis,ci);
                this.annotations.add(annotation);
                i++;
            }

        } catch (IOException e) {
            log.error(e);
        }
    }

}
